package com.anlu.pattern.action.strategy;

import com.anlu.pattern.common.enume.enumfun.StrategyEnum;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 策略的管理类
 */
public class StrategyContext {
    private Discount discount;

    public Map<StrategyEnum, Discount> map = new ConcurrentHashMap<StrategyEnum, Discount>();

    private List<Discount> list = new ArrayList<>();


    /**
     * 在构造方法中添加所有的策略
     */
    public StrategyContext() {
//        list.clear();
//        list.add(new FullDiscount());
//        list.add(new HolidayDiscount());
//        list.add(new NewerDiscount());
//        list.add(new SecondDiscount());

        map.clear();
        map.put(StrategyEnum.STRATEGY_FULL_DISCOUNT,new FullDiscount());
        map.put(StrategyEnum.STRATEGY_NEWER_DISCOUNT,new NewerDiscount());
        map.put(StrategyEnum.STRATEGY_SECOND_DISCOUNT,new SecondDiscount());
        map.put(StrategyEnum.STRATEGY_HOLIDAY_DISCOUNT,new HolidayDiscount());
    }

    public int calculate(StrategyEnum strategyEnum,int money){
       return this.map.get(strategyEnum).calculate(money);
    }


}
